home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / kernel / behavior.d < prev    next >
Text File  |  1996-08-20  |  4KB  |  223 lines

  1. /*
  2.  *
  3.  *    Copyright (c) 1993-1996 Algorithms Corporation
  4.  *    3020 Liberty Hills Drive
  5.  *    Franklin, TN  37067
  6.  *
  7.  *    ALL RIGHTS RESERVED.
  8.  *
  9.  *
  10.  *
  11.  */
  12.  
  13. #include "kernels.h"
  14.  
  15. public    defclass Behavior  {
  16.  
  17.     int      id;    /*  used for hashing and identification  */
  18.     
  19.     char    *name;
  20.     
  21.     CRITICALSECTION    cs;    /*  in support of native threads  */
  22.  
  23.     object    *direct_superclasses;
  24.     int    n_direct_superclasses;
  25.         
  26.     object_list    *direct_subclasses;
  27.         
  28.     object_list    *direct_methods;
  29.         
  30.     object    next;  /*  keep a linked list of classes  */
  31.         
  32.     int    cache_idx;
  33.         
  34.     unsigned    direct_iv_size; /*  direct instance var size  */
  35.     unsigned    effective_iv_size;/*  total instance variable size */
  36.         
  37.     int    direct_iv_offset;
  38.  
  39.  
  40.     /*  list of all superclasses with IVs  */
  41.         
  42.     iv_offset_def_list    *all_superclasses;
  43.  
  44.     /*  instance allocation housekeeping  */
  45.         
  46.     long    sig1;        /*  class signatures        */
  47.     long    sig2;
  48.         
  49.     instance_block    *ib;
  50.     free_list    *fl;
  51.     int    nipib;        /*  number of instances per instance block  */
  52.     int    nib;        /*  number of instance blocks        */
  53.     long    ni;        /*  number of instances            */
  54.     long    nai;        /*  number of available instances    */
  55.         
  56.     int    ncg;        /*  no GC this class flag        */
  57.         
  58.     int    trace;        /*  trace mode                */
  59.         
  60.     ofun    markfun;    /*  additional marking function        */
  61. };
  62.  
  63.  
  64. imeth    char    *gName()
  65. {
  66.     return name; 
  67. }
  68.  
  69. imeth    gDontCollect()
  70. {
  71.     ncg = 1;
  72.     return self;
  73. }
  74.  
  75. imeth    int    gTrace(int mode)
  76. {
  77.     int    pmode = trace;
  78.     trace = mode;
  79.     return pmode;
  80. }
  81.  
  82. imeth    gMarkingMethod(ofun mf)
  83. {
  84.     markfun = mf;
  85.     return self;
  86. }
  87.  
  88. imeth    void    gDoesNotImplement(object gen)
  89. {
  90.     char    buf[100];
  91.  
  92.     ChkArgTyp(gen, 2, GenericFunction);
  93.     if (IsaClass(self))
  94.         sprintf(buf, "\nInstance of class %s doesn't respond to generic %s\n", 
  95.             name, gName(gen));
  96.     else  /*  MetaClass  */
  97.         sprintf(buf, "\nClass %s doesn't respond to generic %s\n", 
  98.             name, gName(gen));
  99.     gError(Dynace, buf);
  100. }
  101.  
  102. imeth    int    gIsKindOf(object cls2)
  103. {
  104.     int    i;
  105.  
  106.     /*  cls2 need not be validated  */
  107.  
  108.     if (self == cls2)
  109.         return 1;
  110.  
  111.     /*  check the super classes  */
  112.  
  113.     for (i=0 ; i < n_direct_superclasses ; ++i)
  114.         if (gIsKindOf(direct_superclasses[i], cls2))
  115.             return 1;
  116.     return 0;
  117. }
  118.  
  119. #ifndef    NOCLASSLIB
  120.  
  121. imeth    gStringRep()
  122. {
  123.     object    s, t;
  124.  
  125.     t = gStringRepValue(self);
  126.     s = vBuild(String, "Class  ", name, "  [ ", t, " ]\n", NULL);
  127.     gDispose(t);
  128.     return s;
  129. }
  130.  
  131. imeth    gStringRepValue()
  132. {
  133.     return vSprintf(String, "<%8.8lx>", self);
  134. }
  135.  
  136. imeth    gSuperClasses()
  137. {
  138.     int    i;
  139.     object    lst;
  140.  
  141.     lst = gNew(LinkObject);
  142.  
  143.     for (i=0 ; i < n_direct_superclasses ; ++i)
  144.         gAddFirst(lst, direct_superclasses[i]);
  145.     return lst;
  146. }
  147.  
  148. imeth    gSubClasses()
  149. {
  150.     object_list    *sc;
  151.     object    lst;
  152.  
  153.     lst = gNew(LinkObject);
  154.  
  155.     for (sc=direct_subclasses ; sc ; sc=sc->next)
  156.         gAddFirst(lst, sc->obj);
  157.     return lst;
  158. }
  159.  
  160. #endif
  161.  
  162. imeth    gCopy()
  163. {
  164.     return gShouldNotImplement(self, "gCopy/gDeepCopy");
  165. }
  166.  
  167. objrtn    Behavior_initialize(void)
  168. {
  169.     static    int    done = 0;
  170.  
  171.     /*  Class creation and some of the methods are initialized by
  172.         the kernel  */
  173.  
  174.     if (done)
  175.         return Behavior_c;
  176.  
  177.     done = 1;
  178.  
  179. /*    Behavior_c = gNewClass(Class, "Behavior", sizeof(Behavior_iv_t), 0, END);    */
  180.  
  181.     iMethodFor(Behavior, gName, Behavior_im_gName);
  182.     iMethodFor(Behavior, gDontCollect, Behavior_im_gDontCollect);
  183.     iMethodFor(Behavior, gTrace, Behavior_im_gTrace);
  184.     iMethodFor(Behavior, gMarkingMethod, Behavior_im_gMarkingMethod);
  185.     iMethodFor(Behavior, gDoesNotImplement, Behavior_im_gDoesNotImplement);
  186.     iMethodFor(Behavior, gIsKindOf, Behavior_im_gIsKindOf);
  187.     iMethodFor(Behavior, gCopy, Behavior_im_gCopy);
  188.     iMethodFor(Behavior, gDeepCopy, Behavior_im_gCopy);
  189.  
  190. #ifndef    NOCLASSLIB
  191.     iMethodFor(Behavior, gStringRep, Behavior_im_gStringRep);
  192.     iMethodFor(Behavior, gStringRepValue, Behavior_im_gStringRepValue);
  193.     iMethodFor(Behavior, gSuperClasses, Behavior_im_gSuperClasses);
  194.     iMethodFor(Behavior, gSubClasses, Behavior_im_gSubClasses);
  195. #endif
  196.     return Behavior_c;
  197. }
  198.  
  199. #if 0  /*  code for the benefit of dpp  */
  200.  
  201. imeth    gNew, gAlloc (){}
  202. ivmeth    vNew(...){}
  203. imeth    gStackAlloc(void *p){}
  204. imeth    ofun    gFindMethod(object generic, int lev){}
  205. imeth    gFindMethodObject(object generic, int lev){}
  206. imeth    int    gInstanceSize(){}
  207.  
  208. #endif
  209.  
  210.  
  211. /*
  212.  *
  213.  *    Copyright (c) 1993-1996 Algorithms Corporation
  214.  *    3020 Liberty Hills Drive
  215.  *    Franklin, TN  37067
  216.  *
  217.  *    ALL RIGHTS RESERVED.
  218.  *
  219.  *
  220.  *
  221.  */
  222.  
  223.